package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZtfLearningRecord;
import com.ruoyi.system.service.IZtfLearningRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程记录Controller
 * 
 * @author ruoyi
 * @date 2025-06-06
 */
@RestController
@RequestMapping("admin/system/record")
@Api(tags = "后台学堂记录相关接口")
public class ZtfLearningRecordController extends BaseController
{
    @Autowired
    private IZtfLearningRecordService ztfLearningRecordService;

    /**
     * 查询课程记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    @ApiOperation("学堂记录数据列表接口")
    public TableDataInfo list(ZtfLearningRecord ztfLearningRecord)
    {
        startPage();
        List<ZtfLearningRecord> list = ztfLearningRecordService.selectZtfLearningRecordList(ztfLearningRecord);
        return getDataTable(list);
    }

    /**
     * 导出课程记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "课程记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZtfLearningRecord ztfLearningRecord)
    {
        List<ZtfLearningRecord> list = ztfLearningRecordService.selectZtfLearningRecordList(ztfLearningRecord);
        ExcelUtil<ZtfLearningRecord> util = new ExcelUtil<ZtfLearningRecord>(ZtfLearningRecord.class);
        util.exportExcel(response, list, "课程记录数据");
    }

    /**
     * 获取课程记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{uuid}")
    @ApiOperation("我的课程记录详情")
    public AjaxResult getInfo(@PathVariable("uuid") String uuid)
    {
        return success(ztfLearningRecordService.selectZtfLearningRecordByUuid(uuid));
    }

    /**
     * 新增课程记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "课程记录", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增我的课程记录")
    public AjaxResult add(@RequestBody ZtfLearningRecord ztfLearningRecord)
    {
       Long userId=SecurityUtils.getUserId();
       //设置用户id
       ztfLearningRecord.setUserId(userId.toString());
       //新增主键id
       ztfLearningRecord.setUuid(IdUtils.simpleUUID());
       return toAjax(ztfLearningRecordService.insertZtfLearningRecord(ztfLearningRecord));
    }

    /**
     * 修改课程记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "课程记录", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改我的课程记录")
    public AjaxResult edit(@RequestBody ZtfLearningRecord ztfLearningRecord)
    {
        return toAjax(ztfLearningRecordService.updateZtfLearningRecord(ztfLearningRecord));
    }

    /**
     * 删除课程记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "课程记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uuids}")
    public AjaxResult remove(@PathVariable String[] uuids)
    {
        return toAjax(ztfLearningRecordService.deleteZtfLearningRecordByUuids(uuids));
    }
}
